# _*_ coding : utf-8 _*_
# @Time: 2024/10/12 15:58
# @Author : 石文帅	
# @File : testbase01修改密码.py
# @Project : python_slfh
from selenium.webdriver.chrome.service import Service

from server.slfhWorkbench import *

from xpathDictionary.slfhXpath import *


class test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.wd = webdriver.Chrome(service=Service(driver_path))
        cls.wd.get(url_path)
        cls.wd.maximize_window()
        login(cls.wd)


    @classmethod
    def tearDownClass(cls):
        cls.wd.quit()
        log.info('----------------------------------------------------------')

    def testbase01修改密码(self):
        """
        修改密码
        :return:
        """
        log.info('testbase01修改密码')
        log.info('点击头像修改密码')
        locate_click(self.wd, homepage['头像'])
        locate_click(self.wd, homepage['修改密码'])

        old_passwd = get_db_data('pageboys', 'password')
        new_passwd = get_db_data('pageboys', 'new_password')

        log.info('新密码长度不够')
        change_passwd(self.wd, '123', '11', '11')
        assert_str_element(self.wd, '(长度为8-18字),密码为数字+字母+特殊字符 8-18位', homepage['新密码提示'])

        log.info('缺少字母')
        change_passwd(self.wd, '123', '11111111', '11111111')
        assert_str_element(self.wd, '(缺少字母) 密码为数字+字母+特殊字符 8-18位', homepage['新密码提示'])

        log.info('缺少特殊字符')
        change_passwd(self.wd, '123', '11111111a', '11111111a')
        assert_str_element(self.wd, '(缺少特殊字符) 密码为数字+字母+特殊字符 8-18位', homepage['新密码提示'])

        log.info('2次新密码不一致')
        change_passwd(self.wd, '123', new_passwd, f'1{new_passwd}2')
        assert_str_element(self.wd, '两次密码不一致！', homepage['确认密码提示'])

        log.info('修改密码原密码错误')
        change_passwd(self.wd, '123', new_passwd, new_passwd)
        assert_str_element(self.wd, '原密码不匹配', homepage['原密码不匹配'])

        log.info('正确更改密码')
        change_passwd(self.wd, old_passwd, new_passwd, new_passwd)
        assert_str_element(self.wd, '登录', loginPage['登录按钮'])

        log.info('把密码修改回去密码')
        login(self.wd, passwd=new_passwd)
        log.info('点击头像修改密码')
        locate_click(self.wd, homepage['头像'])
        locate_click(self.wd, homepage['修改密码'])
        change_passwd(self.wd, new_passwd, old_passwd, old_passwd)
        assert_str_element(self.wd, '登录', loginPage['登录按钮'])
